<template>
  <div id="content">
    <van-nav-bar title="申请详情" left-text="返回" left-arrow fixed @click-left="prev" />

    <van-steps :active="info.status" style="margin-top:60px">
      <van-step>正在审核</van-step>
      <van-step v-if="info.status == 1 && info.is_pass == -1" active-color="#f00">
        <span style="color:#f00">校长审核</span>
        <span style="color:#f00">({{info.pass_name}})</span>
      </van-step>
      <van-step v-else>
        校长审核
        <span v-if="info.status >= 1">({{info.pass_name}})</span>
      </van-step>
      <van-step v-if="info.status == 2 && info.is_edu_pass == -1">
        <span style="color:#f00">教育局审核</span>
        <span style="color:#f00">({{info.edu_pass_name}})</span>
      </van-step>
      <van-step v-else>
        教育局审核
        <span v-if="info.status >= 2">({{info.edu_pass_name}})</span>
      </van-step>
      <van-step>完成</van-step>
    </van-steps>

    <div class="content">
      <van-form validate-first @failed="onFailed">
        <van-field v-model="info.apply_name" label="类型" readonly />

        <!-- 接入申请 -->
        <div v-if="info.type == 1">
          <van-field v-model="info.apply_detail.school_name" label="学校名称" readonly />

          <van-field v-model="info.apply_detail.school_address" label="学校地址" readonly />

          <van-field v-model="info.apply_detail.apply_user" label="申请人" readonly />

          <van-field v-model="info.apply_detail.phone" label="联系电话" readonly />

          <van-field v-model="info.apply_detail.apply_date" label="申请日期" readonly />

          <van-field v-model="info.apply_detail.work_date" label="施工日期" readonly />

          <van-field v-model="info.apply_detail.floor" label="楼层位置" readonly />

          <van-field v-model="imgDesc" @click="imgPreView" label="学校盖章文件" readonly />

          <van-field
            v-if="info.apply_detail.ip_address != null "
            v-model="info.apply_detail.ip_address"
            label="区教育信息中心分配内网IP地址"
            readonly
          />

          <div v-if="info.status == 3">
            <van-field v-model="info.apply_detail.insert_fee_name" label="接入光纤初装费用承担方" readonly />

            <van-field v-model="info.apply_detail.month_fee_name" label="每月光纤信息费用承担方" readonly />
          </div>

          <van-field
            v-model="info.apply_detail.apply_content"
            label="申请内容"
            type="textarea"
            :autosize="{minHeight:100}"
            :minHeight="100"
            readonly
          />
        </div>
        <!-- 拆搬迁申请 -->
        <div v-if="info.type == 2">
          <van-field v-model="info.apply_detail.school_name" label="学校名称" readonly />

          <van-field v-model="info.apply_detail.school_address" label="学校地址" readonly />

          <van-field v-model="info.apply_detail.apply_user" label="申请人" readonly />

          <van-field v-model="info.apply_detail.phone" label="联系电话" readonly />

          <van-field v-model="info.apply_detail.apply_date" label="申请日期" readonly />

          <van-field v-model="info.apply_detail.move_date" label="光纤搬迁日期" readonly />

          <van-field v-model="info.apply_detail.renew_date" label="预期恢复日期" readonly />

          <van-field v-model="info.apply_detail.save_user" label="器件保管者" readonly />

          <van-field v-model="imgDesc" @click="imgPreView" label="学校盖章文件" readonly />

          <div v-if="info.apply_detail.insert_fee != ''">
            <van-field
              name="insert_fee"
              label="接入光纤初装费用承担方"
              :rules="[{required:true,message:'请选择接入光纤初装费用承担方'}]"
            >
              <template #input>
                <van-radio-group
                  v-model="info.apply_detail.insert_fee"
                  direction="horizontal"
                  disabled
                >
                  <van-radio name="1">学校</van-radio>
                  <van-radio name="2">教育局</van-radio>
                </van-radio-group>
              </template>
            </van-field>

            <van-field name="month_fee" label="每月光纤信息费用承担方">
              <template #input>
                <van-radio-group
                  v-model="info.apply_detail.insert_fee"
                  direction="horizontal"
                  disabled
                >
                  <van-radio name="1">学校</van-radio>
                  <van-radio name="2">教育局</van-radio>
                </van-radio-group>
              </template>
            </van-field>
          </div>

          <van-field
            v-model="info.apply_detail.apply_content"
            label="申请内容"
            type="textarea"
            :autosize="{minHeight:100}"
            :minHeight="100"
            readonly
          />
        </div>
        <!-- 虚拟化服务器申请 -->
        <div v-if="info.type == 3">
          <van-field v-model="info.apply_detail.number" label="编号" readonly />

          <van-field v-model="info.apply_detail.write_date" label="填表日期" readonly />

          <van-field v-model="info.apply_detail.identity_name" label="单位名称" readonly />

          <van-field v-model="info.apply_detail.fzr_name" label="负责人姓名" readonly />

          <van-field v-model="info.apply_detail.fzr_mobile" label="负责人手机" readonly />

          <van-field v-model="info.apply_detail.fzr_phone" label="负责人办公电话" readonly />

          <van-field v-model="info.apply_detail.fzr_email" label="负责人邮箱" readonly />

          <van-field v-model="info.apply_detail.adm_name" label="管理人姓名" readonly />

          <van-field v-model="info.apply_detail.adm_mobile" label="管理人手机" readonly />

          <van-field v-model="info.apply_detail.adm_phone" label="管理人办公电话" readonly />

          <van-field v-model="info.apply_detail.adm_email" label="管理人邮箱" readonly />

          <van-field v-model="info.apply_detail.open_port" label="开发端口" readonly />

          <van-field v-model="info.apply_detail.servers_name" label="服务范围" readonly />

          <van-field v-model="info.apply_detail.is_domain" label="是否需要域名" readonly />

          <van-field v-model="info.apply_detail.domain_name" label="域名" readonly />

          <van-field v-model="imgDesc" @click="imgPreView" label="学校盖章文件" readonly />

          <van-field
            v-model="info.apply_detail.apply_content"
            label="申请内容"
            type="textarea"
            :autosize="{minHeight:100}"
            :minHeight="100"
            readonly
          />

          <van-field
            v-if="info.apply_detail.identity_fzr_opinion != null"
            v-model="info.apply_detail.identity_fzr_opinion"
            label="单位负责人意见"
            type="textarea"
            :autosize="{minHeight:100}"
            :minHeight="100"
            readonly
          />

          <van-field
            v-if="info.apply_detail.info_opinion != null"
            v-model="info.apply_detail.info_opinion"
            label="信息中心领导审批意见"
            type="textarea"
            :autosize="{minHeight:100}"
            :minHeight="100"
            readonly
          />

          <van-field
            v-if="info.apply_detail.info_result != null"
            v-model="info.apply_detail.info_result"
            label="信息中心处理结果"
            type="textarea"
            :autosize="{minHeight:100}"
            :minHeight="100"
            readonly
          />
        </div>

        <div v-if="info.reject_reasons != null">
          <van-cell>
            <div>历史驳回原由</div>
            <div v-for="(item,index) in info.reject_reasons" :key="index">
              <div>{{index+1}}.驳回人：{{item.user}}</div>
              <div>时间：{{item.time}}</div>
              <div>原由：{{item.reason}}</div>
            </div>
          </van-cell>
        </div>

        <div style="margin: 16px;" v-if="user.base.role == 0">
          <van-button
            v-if="info.is_pass == -1 || info.is_edu_pass == -1"
            round
            :block="false"
            type="info"
            native-type="button"
            @click="editThing(info.id,info.type)"
          >重新编辑</van-button>
          <!--    <van-button
            plain
            type="info"
            native-type="button"
            round
            :block="false"
            @click="prev"
            style="padding: 0 40px"
          >返回</van-button>-->
        </div>
      </van-form>
    </div>
  </div>
</template>

<script>
import Vue from 'vue'
import { Form, Button, Field, Cell, Step, Steps, ImagePreview, RadioGroup, Radio, NavBar } from 'vant'
import { applyDetail } from '../../api/userApply'
import { getUserInfo } from '../../api/user'

Vue.use(Form).use(Button).use(Field).use(Cell).use(Step).use(Steps).use(ImagePreview).use(RadioGroup).use(Radio).use(NavBar)

export default {
  data()
  {
    return {
      id: 0,
      imgDesc: '点击查看学校盖章文件',
      info: {
        status: 0,
        type: 1,
        apply_detail: {

        }
      },
      user: {
        base: {}
      },
      updateForm: {
        insert_fee: '',
        month_fee: ''
      },
      reject_reason: ''
    }
  },
  created()
  {
    this.id = this.$route.params.id
    this.fetchDetail()
    this.fetchUserInfo()
  },
  methods: {
    fetchDetail()
    {
      applyDetail({ id: this.id }).then(res =>
      {
        this.info = res.data
        this.updateForm.insert_fee = res.data.apply_detail.insert_fee.toString()
        this.updateForm.month_fee = res.data.apply_detail.month_fee.toString()
      })
    },
    fetchUserInfo()
    {
      getUserInfo().then(res =>
      {
        this.user = res.data
      })
    },
    imgPreView()
    {
      ImagePreview(this.info.apply_detail.school_online_file)
    },
    prev()
    {
      this.$router.go(-1)
    },
    editThing(id, type)
    {
      if (type == 1)
      {
        this.$router.push({ name: 'editInsert', params: { id: id } })
      } else if (type == 2)
      {
        this.$router.push({ name: 'editMove', params: { id: id } })
      } else
      {
        this.$router.push({ name: 'editServer', params: { id: id } })
      }
    },
    onFailed(errorInfo)
    {
      console.log('failed', errorInfo)
    }

  }
}
</script>

<style scoped>
.van-step--horizontal {
  text-align: left;
}
</style>
